// File [test/stdx/unique_ptr/02/main.cpp].

/*
    (c) Copyright Alf P. Steinbach 2008.
    Testing std::unique_ptr

    Should only allow polymorphic casts of contained pointer.  This requirement
    doesn't seem to be in the C++0x draft.

    Expected: compiles cleanly, with

    <output>
        Pass
    </output>
*/

#include <alfs/stdx/static_assert.hpp>      // static_assert
#include <alfs/stdx/type_traits.hpp>        // is_same etc.
#include <alfs/stdx/memory.hpp>  // wherever unique_ptr is
#include <cassert>
#include <iostream>

struct NonPolymorphicBase {};
struct NonPolymorphicDerived: NonPolymorphicBase {};

struct PolymorphicBase { virtual ~PolymorphicBase() {} };
struct PolymorphicDerived: PolymorphicBase {};

void testNonPolymorphicCasts()
{
    using namespace std;
    unique_ptr<PolymorphicDerived>   p1( new PolymorphicDerived );
    unique_ptr<PolymorphicBase>      p1Base( move( p1 ) );

    //unique_ptr<NonPolymorphicDerived>   p2( new NonPolymorphicDerived );
    //unique_ptr<NonPolymorphicBase>      p2Base( move( p2 ) );     // Should not compile.
}

int main()
{
    testNonPolymorphicCasts();   
    std::cout << "Pass" << std::endl;
}
